#! /usr/bin/python

import re
import os
from optparse import OptionParser
import shutil
import commands

parser = OptionParser()

parser.add_option('-b', '--block'   , action='store', dest='block_name', help='block_name_for_coverage')
parser.add_option('-c', '--comp_dir', action='store', dest='comp_dir'  , help='comp_dir_path_for_coverage')
parser.add_option('-s', '--sim_dir' , action='store', dest='sim_dir'   , help='sim_dir_path_for_coverage')
parser.add_option('-e', '--el'      , action='store', dest='el_name'   , help='el_name_for_coverage')

(options, args) = parser.parse_args()

block   = options.block_name
cmp_dir = options.comp_dir
sim_dir = options.sim_dir
el_file = options.el_name

all_vdbs = cmp_dir + '/simv.vdb '

def search(dir, suffix):
	global all_vdbs
	for list in os.listdir(dir):       
		path = os.path.join(dir, list)
		if os.path.isfile(path) or '_compile' in path: continue
		elif path.endswith(suffix): 
			all_vdbs += (path + ' ')
		else:
			search(path, suffix)
		
if os.path.isdir('urgReport'):
	shutil.rmtree('urgReport')

search(sim_dir, '.vdb')

print
print all_vdbs
print
print 'urg will merge above coverage database directories.'
print

print el_file
if el_file == None :
	os.system('urg -dir ' + all_vdbs + ' -dbname ' + block + '.vdb' + ' -format both')
else :
	os.system('urg -dir ' + all_vdbs + ' -dbname ' + block + '.vdb' + ' -format both' + ' -elfile ' + el_file + " -excl_strict")

